package com.asia5b.a5mall.middleware.logic.viewmodel.welcome

import android.graphics.Bitmap
import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.base.SimpleNetParams
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.other.UpdateModel
import com.asia5b.a5mall.middleware.utils.EcodeHelper
import com.asia5b.a5mall.middleware.utils.joinComposite
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer

/**
 * Created by zhangyuncai on 2020/8/19.
 */
class AboutVM : SimpleViewModel() {
    val updateModelLiveData = MutableLiveData<UpdateModel>()
    val bitmapLiveData=MutableLiveData<Bitmap>()
    fun checkUpdate() {
        baseSubscribe(baseApi.checkUpdate(), SimpleNetParams(isShowLoading = false), Consumer { updateModel ->
            updateModelLiveData.value=updateModel
        })
    }

    fun createBitmap() {
        Observable.just(1)
                .map {
                    EcodeHelper().createQRImage("https://a5bmall.com/", 200, null)
                }
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(Consumer {
                    bitmapLiveData.value=it
                }, Consumer { it.printStackTrace() }).joinComposite(compositeDisposable)
    }
}